package com.simtop.service.impl;

import com.simtop.dao.RobotStepScoreDao;
import com.simtop.pojo.newrequire.RobotStepScore;
import com.simtop.pojo.newrequire.RobotStepScoreVo;
import com.simtop.service.RobotStepScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lvyongwei
 */
@Service
public class RobotStepScoreServiceImpl implements RobotStepScoreService {

    @Autowired
    private RobotStepScoreDao robotStepScoreDao;

    /**
     * 提交实验结果
     * @param robotStepScore
     * @return
     */
    @Override
    public boolean insertScore(RobotStepScore robotStepScore) {
       return robotStepScoreDao.insertScore(robotStepScore);
    }

    /**
     * 获取实验成绩信息
     * @return
     */
    @Override
    public List<RobotStepScoreVo> getAllRobotStepScore(Integer roleId, Integer userId) {
        return robotStepScoreDao.getAllRobotStepScore(roleId,userId);
    }

    /**
     * 教师评价和心得体会
     * @param scoreId
     * @param commitScore
     * @param evaluation
     * @return
     */
    @Override
    public boolean updateRobotStepScore(Long scoreId, Integer commitScore, String evaluation) {
        return robotStepScoreDao.updateRobotStepScore(scoreId,commitScore,evaluation);
    }

    /**
     * 导出成绩
     * @return
     */
    @Override
    public List<RobotStepScoreVo> exportScore() {
        List<RobotStepScoreVo> robotStepScoreVos = robotStepScoreDao.exportScore();
        robotStepScoreVos.forEach(
                stepScore -> {
                    Integer roleId = stepScore.getRoleId();
                    if(roleId.equals(1)){
                        stepScore.setUserType("管理员");
                    }else if(roleId.equals(2)){
                        stepScore.setUserType("教师");
                    }else if(roleId.equals(3)){
                        stepScore.setUserType("评审专家");
                    }else{
                        stepScore.setUserType("高校学生");
                    }
                }
        );
        return robotStepScoreVos;
    }

    /**
     * 删除实验成绩
     * @param id
     * @return
     */
    @Override
    public boolean deleteScore(Long id) {
        return robotStepScoreDao.deleteScore(id);
    }
}
